package com.tte.common.controller;

import com.tte.common.service.ExcelService;
import com.tte.common.model.tenum.ResultCode;
import com.tte.common.model.vo.ResultBean;
import com.tte.common.model.vo.TestData;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

/**
 * ExcelController
 * @Author: DongWH
 * @Date: 2022/5/10 14:43
 */
@RestController
@RequestMapping("excel")
public class ExcelController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ExcelService excelService;
    @Autowired
    private TestData testData;

    @PostMapping("/read")
    public ResultBean login(Map<String,Object> map) throws IOException {
        map.put("path","C:\\Users\\TTE\\Desktop\\事项及材料.xlsx");
        logger.debug(" 传入参数: {}",map);
        if(!map.containsKey("path")){
            return new ResultBean(ResultCode.PARAMETER_EMPTY.code(),"请选择文件路径",null);
        }
        excelService.readExcel(ObjectUtils.toString(map.get("path")));
        return new ResultBean(ResultCode.OK);
    }
}
